package game.resources;

import game.Coordinate;
import game.enumCompany;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Parsing {

	public static int[] toIntArray(Map<String,String> params) {
		int[] result = { 0, 0, 0, 0, 0, 0, 0 };
		if (params.containsKey("Sackson")) { 
			result[0] = Integer.parseInt(params.get("Sackson"));
		}
		if (params.containsKey("Zeta")) { 
			result[1] = Integer.parseInt(params.get("Zeta"));
		}
		if (params.containsKey("Hydra")) { 
			result[2] = Integer.parseInt(params.get("Hydra"));
		}
		if (params.containsKey("Fusion")) { 
			result[3] = Integer.parseInt(params.get("Fusion"));
		}
		if (params.containsKey("America")) { 
			result[4] = Integer.parseInt(params.get("America"));
		}
		if (params.containsKey("Phoenix")) { 
			result[5] = Integer.parseInt(params.get("Phoenix"));
		}
		if (params.containsKey("Quantum")) { 
			result[6] = Integer.parseInt(params.get("Quantum"));
		}
		
		return result;
	}

	public static Coordinate toCoordinate(Map<String, String> params) {
		Coordinate result = null;
		// if Coordinate==null then exit:
		if (params.containsKey("Exit")) {
			if (params.get("Exit").equalsIgnoreCase("true"))
				return null;
		}
		if (params.containsKey("Tile")) { 
			char x = params.get("Tile").charAt(0);
			String s = params.get("Tile").substring(1);
			int y = Integer.parseInt(s)-1;
			result = new Coordinate(x - 65, y);
		}
		return result;
	}

	public static int[] toTwoInts(Map<String,String> params) {
		int[] result = new int[2];
		if (params.containsKey("Sell")) { 
			result[0] = Integer.parseInt(params.get("Sell"));
		}
		if (params.containsKey("Convert")) { 
			result[1] = Integer.parseInt(params.get("Convert"));
		}
		return result;
	}

	public static enumCompany toEnumCompany(Map<String,String> params){
		enumCompany result = null;
		if (params.containsKey("Company")) { 
			char x = params.get("Company").charAt(0);
			switch (x){
			case 'A':
				result = enumCompany.AMERICA;
				break;
			case 'Z':
				result = enumCompany.ZETA;
				break;
			case 'H':
				result = enumCompany.HYDRA;
				break;
			case 'P':
				result = enumCompany.PHOENIX;
				break;
			case 'S':
				result = enumCompany.SACKSON;
				break;
			case 'Q':
				result = enumCompany.QUANTUM;
				break;
			case 'F':
				result = enumCompany.FUSION;
				break;
			default:
			}
		}

		return result;
	}

	public static List<String> toNameListOfStrings(Map<String,Long> Users) {
		List<String> result = new ArrayList<String>();
		for (String UserName: Users.keySet()) {
			result.add(UserName);
		}
		return result;
	}
	
	public static Map<String,Long> toUsersIDMap(List<Profile> profiles) {
		Map<String,Long> result = new HashMap<String, Long>();
		for (Profile profile: profiles) {
			result.put(profile.getFullName(), profile.getUserID());
		}
		return result;
    }
	
	public static String[] toCompanySellOrderArray(Map<String,String> params) {
		String[] OrderedArray = new String[3];	
		for (int i=0;i<3;i++) {	
			OrderedArray[i] = params.get(Integer.toString(i));
		}
		return OrderedArray;
	}
}

